package com.polytech.diploma.SQLGenerator.Oracle.Statements;

import java.util.List;
import java.util.Map;

import com.polytech.diploma.SQLGenerator.Oracle.Node;
import com.polytech.diploma.SQLGenerator.Oracle.Conditions.Condition;

public class HierarchicalClause implements Node{
	
	protected Condition startWith;
	protected Condition connectBy;
	
	protected boolean noCycle = false;

	private HierarchicalClause(Builder builder) {
		super();
		this.startWith = builder.startWith;
		this.connectBy = builder.connectBy;
		this.noCycle = builder.noCycle;
	}

	public Condition getStartWith() {
		return startWith;
	}

	public Condition getConnectBy() {
		return connectBy;
	}

	public boolean isNoCycle() {
		return noCycle;
	}
	
	public static class Builder {
		private Condition startWith;
		private Condition connectBy;		
		private boolean noCycle = false;
		
		public Builder setStartWith(Condition startWith) {
			this.startWith = startWith;
			return this;
		}
		public Builder setConnectBy(Condition connectBy) {
			this.connectBy = connectBy;
			return this;
		}
		public Builder setNoCycle(boolean noCycle) {
			this.noCycle = noCycle;
			return this;
		}		
		
		public HierarchicalClause build()
		{
			return new HierarchicalClause(this);
		}
	}

	@Override
	public Map<String, List<String>> getTablesWithFields(
			Map<String, List<String>> fieldMap) {
		if(startWith != null)
			fieldMap = startWith.getTablesWithFields(fieldMap);
		if(connectBy != null)
			fieldMap = connectBy.getTablesWithFields(fieldMap);
		return fieldMap;
	}
}
